import { Module } from "vuex"
import { IRootState, IDashboardState } from "@/types/userType"
import { getGoodsCount, getGoodsFavor, getGoodsSale, addressGoodsSale } from "@/api/dashboard/dashboard"
const dashboard: Module<IDashboardState, IRootState> = {
  namespaced: true,
  state() {
    return {
      categoryGoodsCount: [],
      categoryGoodsFavor: [],
      categoryGoodsSale: [],
      addressGoodsSale: [],
    }
  },
  mutations: {
    setGoodsCount(state, data: any[]) {
      state.categoryGoodsCount = data
    },
    setGoodsFavor(state, data: any[]) {
      state.categoryGoodsFavor = data
    },
    setGoodsSale(state, data: any[]) {
      state.categoryGoodsSale = data
    },
    setAddressSale(state, data: any[]) {
      state.addressGoodsSale = data
    },
  },
  actions: {
    async getGoodsCountAction({ commit }, url: string) {
      const goodsCount = await getGoodsCount(url)
      commit("setGoodsCount", goodsCount)
    },
    async getGoodsFavorAction({ commit }, url: string) {
      const goodsFavor = await getGoodsFavor(url)
      commit("setGoodsFavor", goodsFavor)
    },
    async getGoodsSaleAction({ commit }, url: string) {
      const goodsSale = await getGoodsSale(url)
      commit("setGoodsSale", goodsSale)
    },
    async getAddressSaleAction({ commit }, url: string) {
      const addressSale = await addressGoodsSale(url)
      commit("setAddressSale", addressSale)
    },
  },
}

export default dashboard
